
	function productCount(){
		var total=0;      
		var integral=0;
		var price;     
		var number;    

		var myTable=document.getElementById("tableBody").getElementsByClassName("listLi"); 
		if(myTable.length>0){
		for(var i=0;i<myTable.length;i++){
			price=myTable[i].querySelector(".goodsList .pPrice").innerHTML;
			number=myTable[i].querySelector(".goodsList .num").value;
			integral=price*number;
			// console.log(myTable[i].getElementsByClassName("singleAll")[0])			
			myTable[i].getElementsByClassName("singleAll")[0].innerHTML=integral;			
			total+=integral;
		}
		document.getElementById("total").innerHTML=total;
		}
	}
	window.onload=productCount;

	function changeNum(numId,flag){		
		var numId=document.getElementById(numId);
		if(flag=="minus"){
			if(numId.value<=1){
				alert("Incorrect operation");
				return false;
				}
			else{
				numId.value=parseInt(numId.value)-1;
				productCount();
				}
			}
		else{
			numId.value=parseInt(numId.value)+1;
			productCount();			
			}
		}

$(document).ready(function(){
//加的效果
	$(".add").click(function(){
		var n=$(this).prev().val();
		var num=parseInt(n)+1;
		if(num==0){ return;}
		$(this).prev().val(num);
	});
	//减的效果
	$(".jian").click(function(){
		var n=$(this).next().val();
		var num=parseInt(n)-1;
		if(num==0){ return}
		$(this).next().val(num);
	});
	$("#nextStep").click(function(){
		$("#tipBox1").css({'background-color':'#fff'});
		$("#tipBox2").css({'background-color':'#3a8037'});
		$(".content1").css({'display':'none'})
		$(".content2").css({'display':'block'})
	})
	$("a").click(function(){
		Toast('抱歉，我们还木有准备好><',1500);
	})
	$("#lastStep").click(function(){
		$("#tipBox1").css({'background-color':'#fff'});
		$("#tipBox2").css({'background-color':'#fff'});
		$("#tipBox3").css({'background-color':'#3a8037'});
		$(".content1").css({'display':'none'})
		$(".content2").css({'display':'none'})
		$(".content3").css({'display':'block'})		
	})

	function Toast(msg,duration){
	    duration=isNaN(duration)?3000:duration;
	    var m = document.createElement('div');
	    m.innerHTML = msg;
	    m.style.cssText="width: 60%;min-width: 150px;opacity: 0.7;height: 80px;color: rgb(255, 255, 255);line-height: 80px;text-align: center;border-radius: 5px;position: fixed;top: 40%;left: 20%;z-index: 999999;background:#3a8037;font-size: 14px;";
	    document.body.appendChild(m);
	    setTimeout(function() {
	        var d = 0.5;
	        m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
	        m.style.opacity = '0';
	        setTimeout(function() { document.body.removeChild(m) }, d * 1000);
	    }, duration);
	}


	$.ajax({
		type:"get",
		url:"http://localhost/a_world_of_meaty/php/goodsList.php",
		async:true,
		dataType:"json",
		success:function(data){
			console.log(data)
			var str = "";
			data.map(function(item,index){
				str+=`<li class="listLi">
						<ul class="goodsList">
							<li><a href="detail.html?goodsid=${item.goods_id}"><img src="${item.goods_pic}" alt=""></a></li>
							<li><span>${item.goods_name}</span></li>
							<li>
								<div style="clear: both; margin: 0 auto;">
								<em class="jian"  onclick="changeNum('num_1','minus')">-</em>
								<input type="text" value="2" class="num"  id="num_1" />
								<em class="add"  onclick="changeNum('num_1','add')">+</em>
								</div>
							</li>
							<li>￥<span class="pPrice">${item.goods_price}</span></li>
							<li>￥<span class="singleAll">${item.goods_price}</span></li>
							<div style="clear: both;"></div>		
						</ul>
					</li>`
			})
			
			$("#tableBody").html(str);
		}
	});
 })



